<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<script>
  function fn1 () {
     console.log('fn1-this', this)
  }
//   fn1()
  
  let obj1 = {
    count: 0,
    fn2: function () {
      this.count++
      console.log('fn2-this', this, this.count)
      
    }
  }
  
  let obj2 = {
    count: 0,
    fn2: (obj) => {
      obj.count++
      console.log('fn2-this', obj, obj.count) // 箭头函数通过参数更改this指向
    },
    fn3: () => {
      this.count++
      console.log('fn2-this', this, this.count) // window NaN，没有自己的this，会去上层作用域找this
    }
  }
  obj2.fn3.bind(this) // 
  console.log('obj-count', obj2.count) // 0
  obj2.fn2.bind(this, obj2)() // 改变this指向为obj，并执行30行
  console.log('obj-count', obj2.count) // 1


</script>
    
</body>
</html>